package com.aaa.yq127.dao.impl;

import com.aaa.yq127.dao.RoleDao;
import com.aaa.yq127.util.JDBCUtil;

import java.util.List;
import java.util.Map;

public class RoleDaoImpl implements RoleDao {
    @Override
    public List<Map<String, Object>> allRole() {
        String sql = "select * from t_role";
        List<Map<String, Object>> list = JDBCUtil.queryMap(sql);
        if (list.size()==0){
            return null;
        }else {
            return list;
        }
    }

    @Override
    public int insertRole(String rname, String memo, Integer status) {
        String sql = "insert into t_role values(null,?,?,?)";
        int insert = JDBCUtil.update(sql, rname, memo, status);
        return insert;
    }

    @Override
    public int deleteRole(Integer rid) {
       String sql = "delete from t_role where rid = ?";
        int delete = JDBCUtil.update(sql, rid);
        return delete;
    }

    @Override
    public int updateRole(String rname, String memo, Integer status, Integer rid) {
        String sql = "update t_role set rname=?,memo=?,status=? where rid=?";
        int update = JDBCUtil.update(sql, rname, memo, status, rid);
        return update;
    }
}
